package com.yupi.springbootinit.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import javax.annotation.Resource;

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

    private Integer database;

    private String host;

    private String port;

    private String password;

    @Bean
    public RedissonClient redissionClient(){
        Config config = new Config();

        config.useSingleServer()
                .setDatabase(database)
                .setAddress("redis://"+host+":"+port);
        RedissonClient redission= Redisson.create(config);
        return redission;
    }
}
